//By Tyler Gerritsen //2017-11-25 //vtgerritsen@gmail.com //2018-09-08 Added negative number recognition //Serial Commander /* Call getCommand() function regularly. Will return true when a command has been recieved. COMstring will contain the non-numerical string. COMvalue will contain the numerical argument. */ String COMstring; long COMvalue; const char terminator = '/'; boolean getCommand() { static byte i = 0; static char stringChar[20]; boolean newCommand = false; COMstring = ""; COMvalue = 0; if (Serial.available()) { char COMinput = Serial.read(); if (COMinput == terminator) newCommand = true; else if (COMinput > 47 || COMinput == 45) { stringChar[i] = COMinput; i++; } if (newCommand) { byte neg = 0; COMvalue = 0; for (byte j = 0; j < i; j++) { if (!COMvalue && stringChar[j] == '-') neg = 1; else if (stringChar[j] > 57) COMstring += String(stringChar[j]); else COMvalue = COMvalue * 10 + stringChar[j] - '0'; stringChar[j] = 0; } i = 0; if (neg) COMvalue *= -1; } } return newCommand; }